package com.wuliu.controller;

import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.wuliu.common.annotation.Anonymous;
import com.wuliu.common.constant.QueueConstants;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.core.redis.RedisCache;
import com.wuliu.common.core.domain.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 请求控制层
 *
 * @author 散装java
 * @date 2023-02-03
 */
@Api(tags = {"RedisMq控制器"})
@RestController
public class RedisMqController {
    @Resource
    private RedisCache redisCache;

    @Anonymous
    @ApiOperation(value = "添加消息队列")
    @GetMapping("/test-stream")
    public ApiResult<String> stream() {
        Message<Map<String, String>> message = new Message<>();
        message.setId(IdUtil.simpleUUID());
        Map<String, String> map = new HashMap<>(2);
        map.put("mobile", "13543492539");
        map.put("sysAccount", "wuliu");
        message.setContent(map);
        // 将消息添加至消息队列中
        String recordId = redisCache.add(QueueConstants.SEND_SMS_QUEUE_KEY, message);
        return ApiResult.success(recordId);
    }
}
